/*
* 
* 一个解析DEM数据的解析器
* 
* Daniel
* 
* 2018.09.12
* 
* 
* */
define(function () {
    var scope;
    var Dem = function () {
        scope = this;
        var oCanvas = document.createElement("#canvas");
        oCanvas.style.display = "none";
        
        this.oGc = oCanvas.getContext('2d');
        
        this.oImg = new Image();
    };
    
    /*
    *
    * 数据类型为object对象，内容包括一张PNG位图,json高程数据和地理信息位置数据
    *
    * 格式:
    * {
    * png:"../imag/test.png"
    * position:[
    *           {
    *             X:210,
    *             Y:10,},
    *           {
    *             X:250,
    *             Y:10,
    *           },
    *           {
    *             X:250,
    *             Y:100,
    *           },
    *           {
    *             X:210,
    *             Y:100,
    *           },
    *           ],
    * demData:[20,30,40,50,60,70]
    * }
    *
    * */
    
    //初始化数据
    Dem.prototype.prase = function (object) {
        var url = object.png;
        var position = object.position;
        var height = object.demData;
        scope.oImg.src = url;
        scope.oImg.onload = function () {
            scope.oGc.drawImage(scope.oImg, 0, 0);
            var imgData = scope.oGc.getImageData(0, 0, 2763, 1943),
                data = imgData.data;
            debugger;
            var length = data.length;
            var location = length / 3;
            
            for (var i = 0; i < length; i += 4) {
                
                if (data[i] < 150 && data[i + 1] < 150 && data[i + 2] < 150) {
                    data[i] = 255;
                    data[i + 1] = 255;
                    data[i + 2] = 0;
                }
                else {
                    data[i] = 255 - data[i];
                    data[i + 1] = 255 - data[i + 1];
                    data[i + 2] = 255 - data[i + 2];
                }
                
                
            }
            
        }
        
    };
    
    return Dem;
    
    
});